/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package infoplaces2;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;

/**
 *
 * @author Andre Alvarado
 */
public class PlanarPanoramicView extends PlanarPanoramicImage {
   
    //    PlanarPanoramicView(image: RenderedImage)
    //    PlanarPanoramicView(source: PanoramicImage)
    //    fetch(x: double, y: double, z: double): RGBColor
    //    fetch(azimuth: double, zenith: double): RGBColor 
    
    public PlanarPanoramicView(RenderedImage image) {
        super(makeImageArray(image));
    }
    
    public PlanarPanoramicView(PanoramicImage source) {
        super(makeImageArray(source));
    }
    
    //*******ALTERADO******
    public PlanarPanoramicView(CubicPanoramicImage source) throws IOException {
        super(makeImageArray(source));
    }
    
    private static ArrayList<RenderedImage> makeImageArray(RenderedImage image) {
        ArrayList<RenderedImage> result = new ArrayList<>();
        result.add(image); 
        return result;
    }
    
    private static ArrayList<RenderedImage> makeImageArray(PanoramicImage source) {
        //TODO Não implementado.
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    private static ArrayList<RenderedImage> makeImageArray(CubicPanoramicImage source) throws IOException {
        int width = source.images.get(0).getWidth();
        int height = source.images.get(0).getHeight();

        BufferedImage final_image = new BufferedImage(width * 4, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = final_image.createGraphics();

        try {
            //Desenhamos a primeira linha de imagens
            g2d.drawImage((BufferedImage)source.images.get(0), 0, 0, null);
            g2d.drawImage((BufferedImage)source.images.get(1), width, 0, null);
            g2d.drawImage((BufferedImage)source.images.get(2), width * 2, 0, null);
            g2d.drawImage((BufferedImage)source.images.get(3), width * 3, 0, null);
        }
        finally {
            g2d.dispose();
        }
        
        
//        ImageIO.write(final_image, "png", new File("planarPanoramicView.png")); //TODO Para depuração. Apagar depois.
        
        return makeImageArray(final_image);
    }

    @Override
    public int fetch(double x, double y, double z) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int fetch(double azimuth, double zenith) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
